//账户金额显示
$.ajax({
    type:"get",
    datatype:"json",
    url:lastscoreurl+id,
    success:function(d){
        usermoney= Math.round(d.Data)/100;
        $("#lastmoneyword").html(usermoney);
    }
});

var a=document.getElementsByClassName("heads_up_item");
var b=document.getElementsByClassName("detialplace");
//for(var i=0;i< a.length;i++){
//    a[i].index=i;
//    a[i].onclick=function(){
//        for(var r=0;r<b.length;r++){
//            a[r].className="heads_up_item";
//            b[r].style.display="none";
//        }
//        a[this.index].className="heads_up_item is_active";
//        b[this.index].style.display="block";
//    }
//}
//收入
$("#showin").click(function(){
    $("#showin").attr("class","heads_up_item is_active");
    $("#showpay").attr("class","heads_up_item");
    $("#getmoney").css("display","block");
    $("#paymoney").css("display","none");
    $("#getintime").css("display","block");
    $("#paytitle").css("display","none");
});
//支出
$("#showpay").click(function(){
    $("#showin").attr("class","heads_up_item");
    $("#showpay").attr("class","heads_up_item is_active");
    $("#getmoney").css("display","none");
    $("#paymoney").css("display","block");
    $("#getintime").css("display","none");
    $("#paytitle").css("display","block");
});

document.getElementsByClassName("mweb_modal_back_button")[0].onclick=function(){
    history.go(-1);
};
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
//获得当前时间
var currentdate;
//第几页
var currentIndex1=1;//收入
var getover=0;
var getnow="no";
var currentIndex2=1;//支出
var payover=0;
var paynow="no";
var currentIndex3=1;//拒付
var refuseover=0;
var refnow="no";
(function(){
    var date = new Date();
    var seperator1 = "-";
    var year = date.getFullYear();
    var month = date.getMonth() + 1;
    var strDate = date.getDate();
    if (month >= 1 && month <= 9) {
        month = "0" + month;
    }
    if (strDate >= 0 && strDate <= 9) {
        strDate = "0" + strDate;
    }
    //$(".datebox span#dayword").html(strDate+"日");
	$(".datebox span#dayword").html("时间");
    //currentdate = year + seperator1 + month + seperator1 + strDate;
})();
//console.log(currentdate);
//$('#getmoneyinput').val(currentdate);//调整时间
//加载页面
var pagesize=20;
var noday="";
$().ready(
    getmy(noday),

    paymy()
    //refuse()
);
//获取个人收入
function getmy(date){
	if(changetime==="yes"&&getover===0){
		$("#waiting1").css("display","block");
		$("#nonews1").css("display","none");
	};
    if(getover===0){
        $.ajax({
            type:"get",
            datatype:"json",
            url:getmoneyurl+"?userId="+id+"&currentIndex="+currentIndex1+"&pageSize="+pagesize+"&date="+date,
            success:function(d){
                //console.log(d);
                if(!d.Data||d.Data.length===0){
                    getover=1;
                    $("#waiting1").css("display","none");
                    $("#nonews1").css("display","block");
                }
                else{
                    for(var i=0;i<d.Data.length;i++){
                        var imglogo="";
                        var hrefword="";
                        if(d.Data[i].pulu_question.qtype===2){
                            imglogo="<img class='imglogo' src='img/wen01.png'/>";
                            hrefword="questiondetail.html?qid="+d.Data[i].pulu_question.id;
                        }else if(d.Data[i].pulu_question.qtype===3){
                            imglogo="<img class='imglogo' src='img/jing01.png'/>";
                            hrefword="shareexppage.html?eid="+d.Data[i].pulu_question.id;
                        }
                        var tim=/[^\d{4}]\d{2}\-\d{2}/.exec(d.Data[i].pulu_question.ctime)[0].match(/\d{2}\-\d{2}/)[0];
                        $("<div class='box getmoneybox'><a href='"+hrefword+"'><div class='daymoney'>"+tim+"</div>"+imglogo+"<div class='title'>"+ d.Data[i].pulu_question.title+"</div><div class='allmoney'>"+parseFloat(d.Data[i].scoreCountAll)/100+"元</div></a> </div>").insertBefore("#pleasewait1");
                    }
                    if(d.Data.length<pagesize){
                        $("#waiting1").css("display","none");
                        $("#nonews1").css("display","block");
                    }
                }
                if(!date){
                    $("#waiting1").css("display","none");
                    $("#nonews1").css("display","block");
                }
            }
        })
    }
}
//获得个人支出
function paymy(){
    if(payover===0){
        $.ajax({
            type:"get",
            datatype:"json",
            url:paymoneyurl+"?userId="+id+"&currentIndex="+currentIndex2+"&pageSize="+pagesize,
            success:function(d){
                if(!d.Data|| d.Data.length===0){
                    payover=1;
                    $("#waiting2").css("display","none");
                    $("#nonews2").css("display","block");
                }
                else{
                    for(var i=0;i<d.Data.length;i++){
                        var hrefword="";
                        if(d.Data[i].pulu_question.qtype===2){
                            hrefword="questiondetail.html?qid="+d.Data[i].pulu_question.id;
                        }else if(d.Data[i].pulu_question.qtype===3){
                            hrefword="shareexppage.html?eid="+d.Data[i].pulu_question.id;
                        }
                        var tim=/[^\d{4}]\d{2}\-\d{2}/.exec(d.Data[i].pulu_question.ctime)[0].match(/\d{2}\-\d{2}/)[0];
                        $("<div class='box getmoneybox'><a href='"+hrefword+"'> <div class='date'>"+tim+"</div> <div class='title'>"+d.Data[i].pulu_question.title+"</div> <div class='allmoney'>"+parseFloat(d.Data[i].scoreCountAll)/100+"元</div></a></div>").insertBefore("#pleasewait2");
                    }
                    if(d.Data.length<pagesize){
                        $("#waiting2").css("display","none");
                        $("#nonews2").css("display","block");
                    }
                }
            }
        })
    }
}
//获得通知信息
function refuse(){
    if(refuseover===0){
        $.ajax({
            type:"get",
            datatype:"json",
            url:getchangeexpnoticurl+id,
            success:function(d){
                console.log(d);
                if(!d.Data|| d.Data.length===0){
                    refuseover=1;
                    $("#waiting3").css("display","none");
                    $("#nonews3").css("display","block");
                }
                if(d.Data&& d.Data.length>0){
                    console.log(d);
                    var num=0;
                    for(var i=0;i<d.Data.length;i++){
                        num++;
                        var tim=getDateDiff(getDateTimeStamp(d.Data[i].etime));
                        if(!tim){tim="刚刚"};
                        $("<div class='box'> <div class='writerinfor'> <span class='lf'>"+d.Data[i].usernick+"修改了经验</span> <span class='rt'>"+tim+"</span> </div> <h2 class='infotitle'> <a class='question_link' href='shareexppage.html?eid="+d.Data[i].qid+"'> <span class='question_text'>"+d.Data[i].title+"</span> </a> </h2> </div>").insertBefore("#pleasewait3");
                        if(num== d.Data.length){
                            $("#waiting3").css("display","none");
                            $("#nonews3").css("display","block");
                        }
                    }
                }
            }
        })
    }
}
//收入选择时间
var changetime="no";
$('#getmoneyinput').bind('input propertychange', function() {
    //console.log($(this).val());
	changetime="yes";
    var date=$(this).val();
    $(".datebox span#dayword").html($(this).val().match(/\d+$/)[0]+"日收入");
    //时间清空
    $("#getmoneyplace div.getmoneybox").remove();
    $("#waiting1").css("display","block");
    $("#nonews1").css("display","none");
    getover=0;
    getmy(date);
});
//页面滚动
$(window).scroll(function(){
    var mainheight=$(".detialplace").height();
    var windowheight=$(window).height();
    var chajuli=$("#page_wrapper").offset().top - $(window).scrollTop();
    var cz=windowheight-mainheight+10;
    if(chajuli<cz){
        //判断哪个页面滑动
        if($("#getmoney").css("display")==="block"&&changetime==="yes"){
            currentIndex1++;
            var date1=$('#getmoneyinput').val();
            getmy(date1);
        }else if($("#paymoney").css("display")==="block"){
            currentIndex2++;
            paymy();
        }
    }
});
//判断是否为PC 
function IsPC()
{
    var userAgentInfo = navigator.userAgent;
    //alert(userAgentInfo);//Mozilla/5.0 (Windows NT 6.1; WOW64; rv:46.0) Gecko/20100101 Firefox/46.0
    var Agents = new Array("Android", "iPhone", "SymbianOS", "Windows Phone", "iPad", "iPod");
    var flag = true;
    for (var v = 0; v < Agents.length; v++) {
        if (userAgentInfo.indexOf(Agents[v]) > 0) { flag = false; break; }
    }
    return flag;
}
function getOs(){
    var OsObject = "";
    if(navigator.userAgent.indexOf("MSIE")>0) {
        return "MSIE";
    }
    if(isFirefox=navigator.userAgent.indexOf("Firefox")>0){
        return "Firefox";
    }
    if(isSafari=navigator.userAgent.indexOf("Safari")>0) {
        return "Safari";
    }
    if(isCamino=navigator.userAgent.indexOf("Camino")>0){
        return "Camino";
    }
    if(isMozilla=navigator.userAgent.indexOf("Gecko/")>0){
        return "Gecko";
    }
}
if(IsPC()){
    console.log("是电脑");
    $("#dayword").css("display","none");
    //$("#bottomarr").css({"position":"absolute","right":"39px","top":"6px"});
    //$("div.box>div.datebox").css("height","20px");
    $("#getmoneyinput").css({"left":"31px","opacity":"1","width":"auto","fontSize":"15px","textAlign":"center","height":"20px","lineHeight":"20px"});

	$("#daywordpc").css("display","none");
	$("#bottomarr").css("display","none");
    $("#getintime>div").css("padding-top","10px");
    if(getOs()==="Firefox"||getOs()==="MSIE"){
        console.log("浏览器不支持input date控件");
        $("#getmoneyinput").val("年/月/日");
    }else{
        $("#getmoneyinput").css("padding-left","20px")
    }
}else{
    console.log("不是电脑");
    $("#getintime>div").css("padding-top","10px");
    $("#daywordpc").css("display","none");
}
